<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>Linux - 我的Hugo博客</title><meta name="Description" content=""><meta property="og:title" content="Linux" />
<meta property="og:description" content="Linux 系统部署 Java 应用 服务器 Linux
阿里云、华为云、腾讯云
安装虚拟机，虚拟机就是在你的电脑中安装一台虚拟的计算机，内存、CPU、硬盘，Linux 安装到虚拟机中。
CentOS7，企业级 Linux 的发行版，完全开源，完全免费。
安装软件：
 虚拟机 VMware workstation 15 CentOS7 安装 Java 环境 JDK 8 安装 MySQL 8 安装 Tomcat 安装 Xshell 安装 Xftp  安装 VM 安装 Linux 操作系统 CentOS 7 1、解压 CentOS7
2、将解压之后的文件导入 VM，运行即可
3、虚拟机设置
默认的网络配置是桥接模式，直接接入当前的网络环境，如果网络不稳定，IP 会变。
NAT，相当于在 Windows 系统中独立开辟一块新的网络空间，IP 地址固定不变的，无论是否接入外网，都可以访问 CentOS。
4、启动虚拟机，用 root 权限登录
用户名：root
密码：123456
Linux 查询 IP 地址
ifconfig 安装 JDK 1、删除 CentOS 自带的 OpenJDK
2、通过 Xftp 将安装包拷贝到 CentOS 中" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://xls7771.gitee.io/posts/linux/" />
<meta property="article:published_time" content="2020-10-27T23:35:44+08:00" />
<meta property="article:modified_time" content="2020-10-27T23:35:44+08:00" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Linux"/>
<meta name="twitter:description" content="Linux 系统部署 Java 应用 服务器 Linux
阿里云、华为云、腾讯云
安装虚拟机，虚拟机就是在你的电脑中安装一台虚拟的计算机，内存、CPU、硬盘，Linux 安装到虚拟机中。
CentOS7，企业级 Linux 的发行版，完全开源，完全免费。
安装软件：
 虚拟机 VMware workstation 15 CentOS7 安装 Java 环境 JDK 8 安装 MySQL 8 安装 Tomcat 安装 Xshell 安装 Xftp  安装 VM 安装 Linux 操作系统 CentOS 7 1、解压 CentOS7
2、将解压之后的文件导入 VM，运行即可
3、虚拟机设置
默认的网络配置是桥接模式，直接接入当前的网络环境，如果网络不稳定，IP 会变。
NAT，相当于在 Windows 系统中独立开辟一块新的网络空间，IP 地址固定不变的，无论是否接入外网，都可以访问 CentOS。
4、启动虚拟机，用 root 权限登录
用户名：root
密码：123456
Linux 查询 IP 地址
ifconfig 安装 JDK 1、删除 CentOS 自带的 OpenJDK
2、通过 Xftp 将安装包拷贝到 CentOS 中"/>
<meta name="application-name" content="我的Hugo博客">
<meta name="apple-mobile-web-app-title" content="我的Hugo博客"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://xls7771.gitee.io/posts/linux/" /><link rel="prev" href="https://xls7771.gitee.io/posts/mybatisplus/" /><link rel="next" href="https://xls7771.gitee.io/posts/hugo-loveit/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Linux",
        "inLanguage": "zh-cn",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/xls7771.gitee.io\/posts\/linux\/"
        },"genre": "posts","wordcount":  333 ,
        "url": "https:\/\/xls7771.gitee.io\/posts\/linux\/","datePublished": "2020-10-27T23:35:44+08:00","dateModified": "2020-10-27T23:35:44+08:00","publisher": {
            "@type": "Organization",
            "name": "xls"},"author": {
                "@type": "Person",
                "name": "xls"
            },"description": ""
    }
    </script></head>
    <body header-desktop="" header-mobile=""><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : '' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="我的Hugo博客">我的Hugo博客</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="我的Hugo博客">我的Hugo博客</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">Linux</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>xls</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2020-10-27">2020-10-27</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 333 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 2 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents"></nav></div>
            </div><div class="content" id="content"><h1 id="linux-系统部署-java-应用">Linux 系统部署 Java 应用</h1>
<p>服务器 Linux</p>
<p>阿里云、华为云、腾讯云</p>
<p>安装虚拟机，虚拟机就是在你的电脑中安装一台虚拟的计算机，内存、CPU、硬盘，Linux 安装到虚拟机中。</p>
<p>CentOS7，企业级 Linux 的发行版，完全开源，完全免费。</p>
<p>安装软件：</p>
<ul>
<li>虚拟机 VMware workstation 15</li>
<li>CentOS7</li>
<li>安装 Java 环境 JDK 8</li>
<li>安装 MySQL 8</li>
<li>安装 Tomcat</li>
<li>安装 Xshell</li>
<li>安装 Xftp</li>
</ul>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502202046738.png"
        data-srcset="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502202046738.png, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502202046738.png 1.5x, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502202046738.png 2x"
        data-sizes="auto"
        alt="C:\Users\ningn\AppData\Roaming\Typora\typora-user-images\image-20200502202046738.png"
        title="image-20200502202046738" /></p>
<h1 id="安装-vm">安装 VM</h1>
<h1 id="安装-linux-操作系统-centos-7">安装 Linux 操作系统 CentOS 7</h1>
<p>1、解压 CentOS7</p>
<p>2、将解压之后的文件导入 VM，运行即可</p>
<p>3、虚拟机设置</p>
<p>默认的网络配置是桥接模式，直接接入当前的网络环境，如果网络不稳定，IP 会变。</p>
<p>NAT，相当于在 Windows 系统中独立开辟一块新的网络空间，IP 地址固定不变的，无论是否接入外网，都可以访问 CentOS。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203014415.png"
        data-srcset="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203014415.png, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203014415.png 1.5x, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203014415.png 2x"
        data-sizes="auto"
        alt="C:\Users\ningn\AppData\Roaming\Typora\typora-user-images\image-20200502203014415.png"
        title="image-20200502203014415" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203048521.png"
        data-srcset="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203048521.png, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203048521.png 1.5x, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502203048521.png 2x"
        data-sizes="auto"
        alt="C:\Users\ningn\AppData\Roaming\Typora\typora-user-images\image-20200502203048521.png"
        title="image-20200502203048521" /></p>
<p>4、启动虚拟机，用 root 权限登录</p>
<p>用户名：root</p>
<p>密码：123456</p>
<p>Linux 查询 IP 地址</p>
<pre><code>ifconfig
</code></pre><h1 id="安装-jdk">安装 JDK</h1>
<p>1、删除 CentOS 自带的 OpenJDK</p>
<p>2、通过 Xftp 将安装包拷贝到 CentOS 中</p>
<p>3、通过命令安装 JDK</p>
<pre><code>rpm -ivh jdk-8u221-linux-x64.rpm
</code></pre><p>4、配环境变量</p>
<pre><code>JAVA_HOME=/usr/java/jdk1.8.0_221-amd64
CLASSPATH=%JAVA_HOME%/lib:%JAVA_HOME%/jre/lib
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export PATH CLASSPATH JAVA_HOME
</code></pre><p>5、让配置生效</p>
<pre><code>source /etc/profile
</code></pre><h1 id="java-web-应用">Java Web 应用</h1>
<p>1、配置 Tomcat</p>
<p>2、解压缩</p>
<pre><code>tar -zxvf apache-tomcat-9.0.34.tar.gz
</code></pre><p>3、启动 Tomcat</p>
<pre><code>./startup.sh
</code></pre><p>4、CentOS 开放 8080 端口</p>
<ul>
<li>检查防火墙状态</li>
</ul>
<pre><code>firewall-cmd --state
</code></pre><p>running 表示防火墙是开启的，如果你看到的是 not running，防火墙关闭，需要开启</p>
<pre><code>systemctl restart firewalld.service
</code></pre><ul>
<li>开放 8080 端口</li>
</ul>
<pre><code>firewall-cmd --zone=public --add-port=8080/tcp --permanent
</code></pre><ul>
<li>重启防火墙</li>
</ul>
<pre><code>systemctl restart firewalld.service
</code></pre><ul>
<li>重新载入配置</li>
</ul>
<pre><code>firewall-cmd --reload
</code></pre><h1 id="部署-spring-boot-应用">部署 Spring Boot 应用</h1>
<p>IDEA 启动 Spring Boot ，将 Spring Boot 应用打成 jar，通过命令行部署。</p>
<pre><code>java -jar xxx.jar
</code></pre><p>1、将 Spring Boot 应用打包，jar，Maven</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213628286.png"
        data-srcset="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213628286.png, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213628286.png 1.5x, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213628286.png 2x"
        data-sizes="auto"
        alt="C:\Users\ningn\AppData\Roaming\Typora\typora-user-images\image-20200502213628286.png"
        title="image-20200502213628286" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213745177.png"
        data-srcset="C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213745177.png, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213745177.png 1.5x, C:%5cUsers%5cningn%5cAppData%5cRoaming%5cTypora%5ctypora-user-images%5cimage-20200502213745177.png 2x"
        data-sizes="auto"
        alt="C:\Users\ningn\AppData\Roaming\Typora\typora-user-images\image-20200502213745177.png"
        title="image-20200502213745177" /></p>
<p>2、通过命令行启动 jar 即可</p>
<pre><code>java -jar demo.jar
</code></pre><h1 id="安装-mysql">安装 MySQL</h1>
<p>1、通过 Xftp 将 MySQL 安装包拷贝到 Linux</p>
<p>2、解压缩</p>
<pre><code>tar -xvf mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar 
</code></pre><p>3、安装 common、libs、client、server</p>
<p>4、删除自带的 mariadb</p>
<pre><code>rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
</code></pre><p>5、安装命令行</p>
<pre><code>rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm --nodeps --force
</code></pre><p>6、初始化 MySQL</p>
<pre><code>mysqld --initialize
</code></pre><p>7、授权防火墙</p>
<pre><code>chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;
systemctl enable mysqld;
</code></pre><p>8、查看数据库的初始化密码</p>
<pre><code>cat /var/log/mysqld.log | grep password
X(Kr6pe4gjL_
</code></pre><p>9、登录数据库</p>
<pre><code>mysql -uroot -p
</code></pre><p>10、修改密码</p>
<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
</code></pre><p>11、使用新密码登录</p>
<p>12、开启远程访问</p>
<pre><code>create user 'root'@'%' identified with mysql_native_password by 'root';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
</code></pre><p>13、开放 3306 端口</p>
<pre><code>firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
</code></pre><p>14、MySQL 安装默认使用美国的时区，北京时间比美国晚 8 小时</p>
<pre><code>set global time_zone='+8:00';
</code></pre><p>15、创建数据表</p>
<pre><code>create database test character set utf8 collate utf8_general_ci;
use test;
create table user(
    id int primary key auto_increment,
    name varchar(22),
    birthday datetime
);
insert into user(name, birthday) VALUES ('小明','1999-01-01');
insert into user(name, birthday) VALUES ('小红','2000-01-01');
</code></pre><p>war jar</p>
<p>如果你使用的是 SSM 或者 Java WEB（非 Spring Boot）需要通过 war 包进行部署，先把你的应用打成 war 包，丢到外置的 Tomcat 中，启动 Tomcat 服务，进而访问你的应用。</p>
<p>如果你使用的是 Spring Boot，内置了 Tomcat，直接用 jar 部署，使用命令启动即可</p>
<pre><code>java -jar demo.jar
</code></pre></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2020-10-27</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://xls7771.gitee.io/posts/linux/" data-title="Linux"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://xls7771.gitee.io/posts/linux/"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Buffer" data-sharer="buffer" data-url="https://xls7771.gitee.io/posts/linux/" data-title="Linux"><i class="fab fa-buffer fa-fw"></i></a><a href="javascript:void(0);" title="分享到 百度" data-sharer="baidu" data-url="https://xls7771.gitee.io/posts/linux/" data-title="Linux"><i data-svg-src="/lib/simple-icons/icons/baidu.min.svg"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/posts/mybatisplus/" class="prev" rel="prev" title="MyBatisPlus"><i class="fas fa-angle-left fa-fw"></i>MyBatisPlus</a>
            <a href="/posts/hugo-loveit/" class="next" rel="next" title="Hugo LoveIt">Hugo LoveIt<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.2">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2020</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">xls</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"search":{"highlightTag":"em","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":30}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
